<template>
  <div class="haers">
    <el-row>
      <el-col :span="20">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>个人任务</span>
          </div>
          <div class="text item">
            <el-button
              icon="el-icon-document-remove"
              size="mini"
              type="warning"
              style="width: 78px"
              @click="goto_(1)"
              >待处理
              <div style="margin-top: 5px">{{ GRRW.daichuli }}</div>
            </el-button>
            <el-button
              icon="el-icon-refresh-left"
              size="mini"
              type="warning"
              style="width: 78px"
              @click="goto_(2)"
              >被驳回
              <div style="margin-top: 5px">{{ GRRW.beibohui }}</div>
            </el-button>
            <el-button
              icon="el-icon-document-checked"
              size="mini"
              type="success"
              style="width: 78px"
              @click="goto_(3)"
              >已处理
              <div style="margin-top: 5px">{{ GRRW.yichuli }}</div>
            </el-button>
          </div>
        </el-card>
      </el-col>
      <el-col :span="4">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>系统公告</span>
            <el-button style="float: right; padding: 3px 0" type="text"
              >在线宣教</el-button
            >
          </div>
          <div
            class="text item"
            style="text-align: center; line-height: 55px; height: 55px"
          >
            暂无数据
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-row>
      <!-- <el-col :span="16">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>科室汇总</span>
          </div>
          <div class="text item">
            <el-row>
              <el-col :span="4">
                <el-button
                  icon="el-icon-search"
                  circle
                  type="primary"
                  style="margin-left: 20px"
                ></el-button>
                <div>
                  全部事件(<span class="red">{{ BMRWSL.suoyou }}</span
                  >)
                </div>
              </el-col>
              <el-col :span="4">
                <el-button
                  icon="el-icon-refresh-left"
                  circle
                  type="warning"
                  style="margin-left: 20px"
                ></el-button>
                <div>
                  驳回事件(<span class="red">{{ BMRWSL.yibohui }}</span
                  >)
                </div>
              </el-col>
              <el-col :span="4">
                <el-button
                  icon="el-icon-document-remove"
                  circle
                  type="warning"
                  style="margin-left: 20px"
                ></el-button>
                <div>
                  处理中事件(<span class="red">{{ BMRWSL.chulizhong }}</span
                  >)
                </div>
              </el-col>
              <el-col :span="4">
                <el-button
                  icon="el-icon-document-checked"
                  circle
                  type="success"
                  style="margin-left: 20px"
                ></el-button>
                <div>
                  结案事件(<span class="red">{{ BMRWSL.yijiean }}</span
                  >)
                </div>
              </el-col>
              <el-col :span="4">
                <el-button
                  icon="el-icon-circle-close"
                  circle
                  type="danger"
                  style="margin-left: 20px"
                ></el-button>
                <div>
                  已作废事件(<span class="red">{{ BMRWSL.yizuofei }}</span
                  >)
                </div>
              </el-col>
            </el-row>
          </div>
        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>消息提醒</span>
          </div>
          <div
            class="text item"
            style="text-align: center; line-height: 60px; height: 60px"
          >
            暂无数据
          </div>
        </el-card>
      </el-col> -->
      <el-col :span="24">
        <el-table
          :data="tableData"
          style="width: 100%; margin: 10px"
          height="200"
          :header-cell-style="{
            background: 'rgb(246,250,253)',
            color: '#000000',
          }"
          border
          @row-click="Look2"
        >
          <el-table-column prop="events.eventno" label="事件编号" />
          <el-table-column prop="eventTypeName" label="事件类型" />
          <el-table-column prop="dengji" label="事件等级"> </el-table-column>
          <el-table-column prop="patient.name" label="患者姓名" />
          <el-table-column prop="events.occtime" label="发生时间" />
          <el-table-column prop="events.reporttime" label="上报时间" />
          <el-table-column prop="taskStatusName" label="状态">
            <!-- <template slot-scope="scope">
              <span v-if="scope.row.events.status == 0 && nowOrd == '牟定'"
                >处理中</span
              >
              <span v-if="scope.row.events.status == 0 && nowOrd != '牟定'"
                >驳回到上报人</span
              >
              <span v-if="scope.row.events.status == 1">处理中</span>
              <span v-if="scope.row.events.status == 2">已结案</span>
              <span v-if="scope.row.events.status == 3">已归档</span>
            </template> -->
          </el-table-column>
          <el-table-column prop="events.status" label="追踪状态">
            <template slot-scope="scope">
              {{ scope.row.traceStatus == true ? "已追踪" : "未追踪" }}
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="240">
            <template slot-scope="scope">
              <!-- <el-button
                size="mini"
                @click="Look(scope.row.events, 1)"
                type="text"
                >事件状态</el-button
              > -->
              <el-button size="mini" @click="Look(scope.row, 2)" type="text"
                >查看表单</el-button
              >
              <el-button
                v-if="!scope.row.traceStatus"
                size="mini"
                @click="ToSet(scope.row.events, 'yes')"
                type="text"
                >追踪事件</el-button
              >
              <el-button
                v-if="scope.row.traceStatus"
                size="mini"
                @click="ToSet(scope.row.events, 'no')"
                type="text"
                >取消追踪</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <div class="block" style="text-align: center; margin-top: 5px">
          <el-pagination
            layout="prev, pager, next"
            :page-size="query.pageSize"
            :current-page="query.currentPage"
            :total="total"
            @current-change="page_change"
          >
          </el-pagination>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="14">
        <el-card class="box-card">
          <el-select
            v-model="year1"
            size="mini"
            @change="getNDFLTJ(), drawLine()"
          >
            <el-option
              v-for="item in yearList"
              :key="item"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select>
          <div class="text item">
            <div id="a" :style="{ width: '100%', height: '200px' }"></div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="10">
        <el-card class="box-card">
          <el-select
            v-model="year2"
            size="mini"
            @change="getJ12YTJ(), drawLine()"
          >
            <el-option
              v-for="item in yearList"
              :key="item"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select>
          <div class="text item">
            <div id="b" :style="{ width: '100%', height: '200px' }"></div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-card class="box-card">
      <el-select v-model="year3" size="mini" @change="getNDKSTJ()">
        <el-option
          v-for="item in yearList"
          :key="item"
          :label="item"
          :value="item"
        >
        </el-option>
      </el-select>
      <el-select
        v-model="SectionId"
        size="mini"
        @change="getNDKSTJ()"
        clearable
        filterable
      >
        <el-option
          v-for="item in SectionList"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        >
        </el-option>
      </el-select>
      <div class="text item">
        <div id="c" :style="{ width: '100%', height: '300px' }"></div>
      </div>
    </el-card>
  </div>
</template>
<script>
let echarts = require("echarts/lib/echarts");
// 引入提示框和title组件
require("echarts/lib/component/tooltip");
require("echarts/lib/component/title");
export default {
  data() {
    return {
      GRRW: {}, // 个人任务
      BMRWSL: {}, // 部门任务
      NDFLTJ: {}, // 年度分类统计
      J12YTJ: {}, // 近12月统计
      NDKSTJ: {}, // 年度各科室统计
      yearList: [],
      year1: "2025",
      year2: "2025",
      year3: "2025",
      SectionList: [],
      SectionId: "",
      // 首页加
      query: {
        currentPage: 1,
        pageSize: 15,
        filter: {
          key: "",
          occDept: "",
          reportDept: "",
          grade: "",
          occTimeStart: "",
          occTimeEnd: "",
          reportTimeStart: "",
          reportTimeEnd: "",
          name: "",
          eventNo: "",
          status: "",
          patientType: "",
          evaluate: "",
          endStateluate: "",
          EventType: 3,
        },
      },
      tableData: [],
      total: 0,
    };
  },
  created() {
    const currentDate = new Date();
    const currentYear = currentDate.getFullYear();

    // 用于存储近五年年份的数组
    const lastFiveYears = [];

    // 循环计算近五年的年份
    for (let i = 0; i < 5; i++) {
      lastFiveYears.push(currentYear - i);
    }
    this.yearList = lastFiveYears;
    this.$get("/Aers/Home/SectionList").then((res) => {
      this.SectionList = res.data;
    });
    this.getGRSJ();
    this.getBMRWSL();
    this.getNDFLTJ();
    this.getJ12YTJ();
    this.getNDKSTJ();
  },
  mounted() {
    setTimeout((_) => {
      this.drawLine();
    }, 1000);
    this.getTable();
  },
  methods: {
    drawLine() {
      // 绘制图表
      echarts.init(document.getElementById("a")).setOption({
        title: { text: this.year1 + "年全国各类事件占比图" },
        tooltip: {
          trigger: "item",
        },
        legend: {
          orient: "vertical",
          left: "right",
        },
        series: [
          {
            name: "访问来源",
            type: "pie",
            radius: "50%",
            data: this.NDFLTJ,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      });
      echarts.init(document.getElementById("b")).setOption({
        title: { text: "近12个月全院每月上报事件例数" },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: "shadow", // 默认为直线，可选为：'line' | 'shadow'
          },
        },
        legend: {
          left: "right",
          data: "事件例数",
        },
        xAxis: {
          type: "category",
          data: this.J12YTJ.月份,
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: this.J12YTJ.data,
            type: "bar",
            emphasis: {
              focus: "series",
            },
          },
        ],
      });
      echarts.init(document.getElementById("c")).setOption({
        title: { text: this.year3 + "年全院各科室上报/发生例数" },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: "shadow", // 默认为直线，可选为：'line' | 'shadow'
          },
        },
        legend: {
          left: "right",
          data: this.NDKSTJ.类型,
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            data: this.NDKSTJ.时间,
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
        series: this.NDKSTJ.items,
      });
    },
    getGRSJ() {
      this.$get("/Aers/Home/GetMineTaskQuantity").then((res) => {
        this.GRRW = res.data;
      });
    },
    getBMRWSL() {
      this.$get("/Aers/Home/GroupQuantity").then((res) => {
        this.BMRWSL = res.data;
      });
    },
    getNDFLTJ() {
      this.$get("/Aers/Home/EventCategory?year=" + this.year1).then((res) => {
        var list = [];
        for (var i in res.data) {
          list.push({
            value: res.data[i].count,
            name: res.data[i].eventtype,
          });
        }
        this.NDFLTJ = list;
      });
    },
    getJ12YTJ() {
      this.$get("/Aers/Home/RecentTwelveMonths?year=" + this.year2).then(
        (res) => {
          let 月份 = [];
          let data = [];
          for (var i in res.data) {
            月份.push(res.data[i].month);
            data.push(res.data[i].count);
          }
          this.J12YTJ = {
            月份,
            data,
          };
          this.drawLine();
        }
      );
    },
    getNDKSTJ() {
      this.$get(
        "/Aers/Home/YearGroupQuantity?year=" +
          this.year3 +
          "&sectionId=" +
          this.SectionId
      ).then((res) => {
        let 时间 = [];
        let 类型 = [];
        let items = [];
        for (var i in res.data) {
          时间.push(res.data[i].time);
        }
        for (var j in res.data[0].arr) {
          类型.push(res.data[0].arr[j].name);
          let data = [];
          for (var k in res.data) {
            data.push(res.data[k].arr[j].value);
          }
          items.push({
            name: res.data[0].arr[j].name,
            type: "bar",
            emphasis: {
              focus: "series",
            },
            data: data,
          });
        }
        this.NDKSTJ = {
          时间,
          类型,
          items,
        };
        this.drawLine();
      });
    },
    goto_(flag) {
      var url = "";
      if (flag == 1) {
        url = "/pending";
      }
      if (flag == 2) {
        url = "/Rejected";
      }
      if (flag == 3) {
        url = "/Processed";
      }
      this.$router.push(url);
    },
    // 首页列表加
    getTable() {
      var body = this.query;
      this.$post("/Aers/ReportEvent/GetTaskEventList", body).then((res) => {
        this.tableData = res.data.list;
        this.total = res.data.total;
      });
    },
    page_change(val) {
      this.query.currentPage = val;
      this.getTable();
    },
    Look(row, flag) {
      if (flag == 1) {
        console.log(row);
        this.$get(
          "/Aers/ReportEvent/GetTaskList?eventNo=" + row.events.eventno
        ).then((res) => {
          this.事件状态 = res.data;
        });
        return;
      }
      if (flag == 2) {
        // window.open("/#/BD?id=" + row.id + "&flag=" + true);
        // this.$router.push(
        //   "/BD?id=" +
        //     row.id +
        //     "&flag=" +
        //     true +
        //     "&Token=" +
        //     localStorage.getItem("Token")
        // );
        this.$router.push(
          "/BD?id=" +
            row.events.id +
            "&flag=" +
            true +
            "&Token=" +
            localStorage.getItem("Token") +
            "&reportdeptStr=" +
            row.reportdeptStr +
            "&reportuserStr=" +
            row.reportuserStr +
            "&eventTypeName=" +
            row.eventTypeName
          // "&Btn_show=" +
          // true
        );
        return;
      }
    },
    Look2(row) {
      this.$get(
        "/Aers/ReportEvent/GetTaskList?eventNo=" + row.events.eventno
      ).then((res) => {
        this.事件状态 = res.data;
      });
    },
    ToSet(row, flag) {
      if (flag == "yes") {
        let body = {
          eventno: row.eventno,
        };
        this.$post("Aers/DataTrace/Create", body).then((res) => {
          this.getTable();
          this.$message.success("操作成功！");
        });
        return;
      }
      if (flag == "no") {
        this.$deleteF("Aers/DataTrace/Delete?eventno=" + row.eventno).then(
          (res) => {
            this.getTable();
            this.$message.success("操作成功！");
          }
        );
        return;
      }
    },
  },
};
</script>
<style scoped>
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}
.el-card /deep/ .el-card__header {
  padding: 10px 20px;
  background-color: #e2e2e2;
}
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}

.box-card {
  margin: 10px;
}
.card-ipt {
  width: 200px;
}
.ipt-text {
  font-weight: bold;
}
.red {
  font-weight: 600;
  color: #ff0000;
}
.content {
  width: 90px;
  height: 50px;
  color: #1e8bc2;
  font-weight: bold;
  border-radius: 5px;
  border: 1px #1e8bc2 solid;
}
</style>